package com.yqb.study.common.log;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.yqb.study.common.bean.DbMapperContextHolder;
import com.yqb.study.modular.persistence.dao.OperateLogMapper;
import com.yqb.study.modular.persistence.model.OperateLog;

import java.util.TimerTask;

/**
 * 日志输出任务创建工厂
 */
public class LogPersistTaskFactory {

    private static Logger logger = LoggerFactory.getLogger(LogPersistTaskFactory.class);
    
    private static OperateLogMapper operateLogMapper = DbMapperContextHolder.getMapper(OperateLogMapper.class);

    public static TimerTask operateLog(OperateLog operateLog) {
        return new TimerTask() {
            @Override
            public void run() {
                try {
                    operateLogMapper.insert(operateLog);
                } catch (Exception e) {
                    logger.error("保存日志异常!", e);
                }
            }
        };
    }
}
